<template>
  <el-container direction="vertical" style="padding: 10px">
    <el-form size="mini">
      <el-form-item label="真实姓名">
        <el-input v-model="formData.realName"></el-input>
      </el-form-item>
      <el-form-item label="账号">
        <el-input v-model="formData.username"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="formData.phoneNum" type="number"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="formData.password" type="password" show-password></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="formData.roleId" placeholder="请选择">
          <el-option v-for="item in roleList" :value="item.id">{{item.roleType}}</el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleUserAdd" :disabled="addDisable">新增</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
  export default {
    name: "index",
    data: function () {
      return {
        formData: {
          realName: null,
          phoneNum: null,
          username: null,
          roleId: null,
          password: null,
        },
        roleList: [],
        addDisable: false,
      }
    },
    created() {
      this.getRoleList();
    },
    methods: {
      getRoleList() {
        this.$api.roleList().then(res => {
          this.roleList = res;
        })
      },
      handleUserAdd() {
        this.$api.userSave(this.formData).then(res => {
          this.addDisable = true;
        })
      }
    }
  }
</script>

<style scoped>

</style>
